package com.yangyu.service;

import com.yangyu.currency.StatusCode;
import com.yangyu.mapper.TagMapper;
import com.yangyu.message.BaseRsp;
import com.yangyu.message.tag.TagVo;
import com.yangyu.pojo.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @author 一碗鱼汤面
 * @version V1.0
 * @Package com.yangyu.service
 * @date 2020/12/20 21:32
 */
@Service
public class TagService {
    @Autowired
    private TagMapper tagMapper;

    /**
     * 查询热门标签
     *
     * @return
     */
    public BaseRsp getHotTags() {
        List<Long> hotTagsId = tagMapper.getHotTagIds();
        if (CollectionUtils.isEmpty(hotTagsId)) {
            return new BaseRsp();
        }
        List<Tag> hotTags = tagMapper.getHotTags(hotTagsId);
        return new BaseRsp(hotTags);
    }

    /**
     * 查询标签详情
     *
     * @return
     */
    public BaseRsp getTagDetails() {
        List<TagVo> tagDetails = tagMapper.getTagDetails();

        return new BaseRsp(tagDetails);
    }

    public BaseRsp addFlag(Tag tag) {
        try {
            tagMapper.addFlag(tag);
        } catch (Exception e) {
            return new BaseRsp(StatusCode.DB_ERROR, "add flag error");
        }
        return new BaseRsp();
    }
}
